package cn.lhl.web.controller;

import cn.lhl.domain.system.User;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {
    protected HttpServletRequest request;
    protected HttpSession session;
    protected HttpServletResponse response;
    protected Model model;
    protected User user;

    protected String companyId;
    protected String companyName;

    @ModelAttribute
    public void init(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model) {
        this.request = request;
        this.response = response;
        this.session = session;
        this.model = model;

        User user = (User) session.getAttribute("loginUser");

        if (user != null) {
            this.user = user;
            this.companyId = user.getCompanyId();
            this.companyName = user.getCompanyName();
        }

    }
}
